package org.infodavid.common.persistence.impl;

import org.infodavid.common.persistence.IQueryParameter;

/**
 * The Class QueryParameterImpl.
 */
class QueryParameterImpl implements IQueryParameter {

	/** serialVersionUID. */
	private static final long serialVersionUID = -3891044330026331828L;

	/** The name. */
	private String name;

	/** The column. */
	private String columnName;

	/** The value. */
	private Object value;

	/** The type. */
	private EParameterType type;

	/**
	 * The Constructor.
	 */
	protected QueryParameterImpl() {
		super();
	}

	/**
	 * The Constructor.
	 * @param pName the p name
	 */
	protected QueryParameterImpl(final String pName) {
		super();

		name = pName;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IQueryParameter#getName()
	 */
	public String getName() {
		final String result;

		if (name == null) {
			result = columnName;
		}
		else {
			result = name;
		}

		return result;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IQueryParameter#getValue()
	 */
	public Object getValue() {
		return value;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IQueryParameter#getColumnName()
	 */
	public String getColumnName() {
		final String result;

		if (columnName == null) {
			result = name;
		}
		else {
			result = columnName;
		}

		return result;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IQueryParameter#getType()
	 */
	public EParameterType getType() {
		return type;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IQueryParameter#init()
	 */
	public void init() {
		name = null;
		columnName = null;
		value = null;
		type = null;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IQueryParameter#setValue(java.lang.Object)
	 */
	public IQueryParameter setValue(final Object pValue) {
		value = pValue;

		return this;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IQueryParameter#setName(java.lang.String)
	 */
	public IQueryParameter setName(final String pValue) {
		name = pValue;

		return this;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IQueryParameter#setColumnName(java.lang.String)
	 */
	public IQueryParameter setColumnName(final String pValue) {
		columnName = pValue;

		return this;
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.persistence.IQueryParameter#setType(org.infodavid.common.persistence.
	 * IQueryParameter.EParameterType)
	 */
	public IQueryParameter setType(final EParameterType pValue) {
		type = pValue;

		return this;
	}

	/**
	 * To string.
	 * @return the string representation
	 */
	public String toString() {
		final StringBuffer buffer = new StringBuffer();

		buffer.append(super.toString());
		buffer.append("[");
		buffer.append("name = ").append(name);
		buffer.append(" value = ").append(value);
		buffer.append("]");

		return buffer.toString();
	}
}
